package org.dawning.shop.category.vo;

import lombok.Data;
import org.dawning.shop.category.entity.BaseCategory;
import org.dawning.shop.category.entity.Type;
import org.dawning.shop.core.base.BaseEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by L on 2017/6/13.
 * 分类对应的属性
 */
@Data
public class CategoryVO extends BaseEntity {

    private String id;

    private String parentId;

    private String categoryName;

    private String categoryCode;
    private List<Type> typeList;

    private int sort;

    List<CategoryVO> childrenList;

    public void addChildCate(CategoryVO vo) {
        if (this.childrenList==null)this.childrenList = new ArrayList<>();
        this.childrenList.add(vo);
    }


    /**
     * 数据库类型转VO
     * @param category
     * @return
     */
    public static CategoryVO getVO(BaseCategory category){
        if (category==null)return null;
        CategoryVO categoryVO = new CategoryVO();
        categoryVO.setId(category.getId());
        categoryVO.setCategoryCode(category.getCategoryCode());
        categoryVO.setCategoryName(category.getCategoryName());
        categoryVO.setParentId(category.getParentId());
        categoryVO.setTypeList(category.getTypeList());
        return categoryVO;
    }
    /**
     * 数据库类型转VO,批量
     * @param list
     * @return
     */
    public static List<CategoryVO> getVOList(List<BaseCategory> list) {
        if (list==null)return null;
        List<CategoryVO> vos = new ArrayList<>();
        for (BaseCategory category:list){
            CategoryVO categoryVO = getVO(category);
            vos.add(categoryVO);
        }
        return vos;
    }



}
